* Multiproduct Firms, Horizontal Mergers, and International Trade
* Jackie M.L. Chan, Michael Irlacher, and Michael Koch

* This do file runs additional regressions for domestic market outcomes.

* Setup
* From Do File #P15
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_all_cvrnr_khandelwal_sitc5r2.dta", clear
collapse (mean) irge0, by(cvrnrA aarA)

tempfile temp1
save `temp1.dta', replace

* Main data
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\regression_data_domestic.dta", clear

merge 1:1 cvrnrA aarA using `temp1.dta', keep(match master) nogen

xtset group aarA
gen Lirge0 = L.irge0
gen L2irge0 = L2.irge0
gen L3irge0 = L3.irge0

egen irge0y = rowmean(irge0 Lirge0 L2irge0 L3irge0) if aar==aarA

egen mirge0y = mean(irge0y), by(cvrnrA)
sum irge0, d
gen diff = 1 if irge0>r(p50) & irge0!=. & acquirer==0
replace diff = 0 if irge0<=r(p50) & acquirer==0
replace diff = 1 if irge0>r(p50) & irge0!=. & acquirer==1 
replace diff = 0 if irge0<=r(p50) & acquirer==1 

gen p = (p1==1 | p2==1 | p3==1)

foreach x in lnnprod {
areg `x' p4 p3 p2 p1 test m1 m2 m3 m4 D_AA_1-D_AA_22 if minemployee_cvrnr>=10 & diff==1, absorb(cvrnrA) cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA4.txt", keep(p4 p3 p2 p1 test m1 m2 m3 m4 D_AA_1-D_AA_22) bdec(4) sdec(4) nocons nonotes

areg `x' p4 p3 p2 p1 test m1 m2 m3 m4 D_AA_1-D_AA_22 if minemployee_cvrnr>=10 & diff==0, absorb(cvrnrA) cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA4.txt", keep(p4 p3 p2 p1 test m1 m2 m3 m4 D_AA_1-D_AA_22) bdec(4) sdec(4) nocons nonotes 

reg `x' p D_AA_1-D_AA_22 i.group_cvrnr if aar!=. & minemployee>=10 & diff==1, cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_A7.txt", keep(p D_AA_1-D_AA_22) bdec(4) sdec(4) nocons nonotes 

reg `x' p D_AA_1-D_AA_22 i.group_cvrnr if aar!=. & minemployee>=10 & diff==0, cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_A7.txt", keep(p D_AA_1-D_AA_22) bdec(4) sdec(4) nocons nonotes 

did_imputation lnnprod group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & diff==1, fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA4.txt", bdec(4) sdec(4) nocons nonotes 

did_imputation lnnprod group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & diff==0, fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA4.txt", bdec(4) sdec(4) nocons nonotes
}
